
package widgets;

import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.effect.DropShadow;
import javafx.scene.input.MouseEvent;

public class NextStepButtonWidget extends CustomNode {

    public var x:Number = 0;
    public var y:Number = 0;

    public var textXoffset:Number = 0;
    public var textYoffset:Number = 0;

    public var phrase:String = "42";
    public var font: Font = Font {
        size: 18;
    }

    public var isPressed: Boolean = false;

    def shadow: DropShadow = DropShadow {
                            color: Color.BLACK;
                            offsetX: 3
                            offsetY: 3
                            radius: 3
                        }

    def nextStepButton: Rectangle = Rectangle {
                        translateX: x
                        translateY: y
                        width: 150
                        height: 30
                        arcWidth: 20
                        arcHeight: 55
                        stroke: Color.BLACK
                        effect: shadow;
                        onMouseEntered: function(evt: MouseEvent):Void {
                            shadow.color = Color.BLUE;
                            shadow.radius += 3;
                        }
                        onMouseExited: function(evt: MouseEvent):Void {
                            shadow.color = Color.BLACK;
                            shadow.radius -= 3;
                        }
                        onMousePressed: function (evt: MouseEvent):Void {
                            nextStepButton.translateX += 1;
                            nextStepButton.translateY += 1;
                            shadow.offsetX -= 1;
                            shadow.offsetY -= 1;
                            text.translateX += 1;
                            text.translateY += 1;
                            isPressed = true;
                        }
                        onMouseReleased: function( e: MouseEvent ):Void {
                            nextStepButton.translateX -= 1;
                            nextStepButton.translateY -= 1;
                            shadow.offsetX += 1;
                            shadow.offsetY += 1;
                            text.translateX -= 1;
                            text.translateY -= 1;
                            isPressed = false;
                        }
                        fill: Color.WHITE;
                    }
    def text: Text = Text {
                            font: font
                            translateX: x + textXoffset
                            translateY: y + textYoffset
                            content: phrase
                        }

    def content:Group = Group {}

    protected override function create(): Node {

        content.content = [nextStepButton, text];
        return content;
    }
}
